import 'package:boss/ui/page/commodity/categories/page/plusCommodityMode/page/plusCommodityByFormField/page/materialSetting/model/commodity_material.dart';
import 'package:boss/ui/widget/form/base_text_form_field.dart';
import 'package:boss/ui/widget/image/base_image.dart';

import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class MaterialItem extends StatelessWidget {
  final CommodityMaterial data;
  final VoidCallback onDeleted;
  final ValueChanged<String> onNameChanged;
  final ValueChanged<String> onPriceChanged;

  const MaterialItem({
    Key key,
    @required this.data,
    this.onDeleted,
    this.onNameChanged,
    this.onPriceChanged,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Row(
        children: <Widget>[
          Expanded(
            child: BaseTextFormField(
              prefixText: '名称',
              hintText: '例如：香菜',
              maxLength: 10,
              initialValue: data.name,
              onChanged: onNameChanged,
            ),
          ),
          SizedBox(
            width: 40.w,
          ),
          Expanded(
            child: BaseTextFormField(
              prefixText: '价格',
              hintText: '请输入',
              suffixText: '元',
              inputFormatters: [FilteringTextInputFormatter.allow(RegUtil.numberReg)],
              keyboardType: TextInputType.numberWithOptions(decimal: true),
              initialValue: data.price,
              onChanged: onPriceChanged,
            ),
          ),
          Container(
            margin: EdgeInsets.only(
              left: 10.w,
            ),
            child: GestureDetector(
              onTap: onDeleted,
              child: BaseImage(
                'assets/image/close_icon.png',
                width: 30.w,
                height: 30.w,
                fit: BoxFit.contain,
              ),
            ),
          ),
        ],
      ),
    );
  }
}
